﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Formular;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Weblications.Sango.Protocol;

namespace Pixysoft.Weblications.Sango.Command.equipment
{
    partial class SangoEquipmentHandler
    {
        public eqm_repositoryexpand eqm_repositoryexpand()
        {
            string userCode = SangoManager.Authentication();

            eqm_repositoryexpand response = ReflectionManager.CreatePojo<eqm_repositoryexpand>();
            response.Succeed = false;


            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);
            Entities.Usr_Property property = UsrPropertyDao.getProperty(userCode);

            long goldprice = EquipmentFormular.getNextStoragePrice(property.Repositorycount);

            if (!UsrProfileDao.tryDecreaseGoldValue(profile, goldprice))
            {
                response.Message = "金币余额不足";
                return response;
            }

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;


            command.Begin(delegate()
            {
                property.Repositorycount = property.Repositorycount + 1;

                command.Update(property);

                command.Update(profile);

                command.Commit();
            });


            response.profile = UsrProfileFacade.ToProfile(profile);
            response.property = UsrProfileFacade.ToProperty(property);
            response.Succeed = true;
            return response;
        }


    }
    public interface eqm_repositoryexpand : ISangoResponse
    {
        player_profile profile { get;set;}

        player_property property { get;set;}
    }
}
